package com.zzj.线程池;

import org.junit.Test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author: zzj
 * @date: 2018/01/05
 * Time: 14:48
 */
public class ThreadDemo implements Runnable{
    int i=0;
    @Override
    public void run() {
        try {
            System.out.println("ssss");
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        for (int i = 0; i < 100; i++) {
            executorService.submit(new ThreadDemo());
        }
        executorService.shutdown();
        boolean loop=false;
        while(!loop){
            loop=executorService.awaitTermination(1,TimeUnit.SECONDS);
        }
        System.out.println("结束");

    }

}
